package com.compiler.lexico;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.HashMap;
import java.util.Map;

public class State {
	private String name;
	private Map<Character, Transaction> transactions;
	
	public State(String name) {
		this.name = name;
		this.transactions = new HashMap<Character, Transaction>();
	}
	
	public void addTransacion(Character c, Transaction t) {
		this.transactions.put(c, t);
	}
	
	public Transaction getTransaction(Character c) {
		return transactions.get(c);
	}
	
	public State getNextState(Character c) {
		return this.getTransaction(c).getNextState();
	}
	
	public void execAction(Transaction transaction, RandomAccessFile raf) throws IOException {
		transaction.exec(raf);
	}
	
	public State getNextState(Character c, RandomAccessFile raf) throws IOException {
		Transaction transaction = this.getTransaction(c);
		this.execAction(transaction, raf);
		return transaction.getNextState();
	}
	
	public String getName() { return this.name; }
	
	public String toString() {
		return this.name; 
	}

}
